package cloud.xlh.my_system.middle_aware.mq.queue;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/2/14 14:41
 * @ Description:
 */
@Configuration
public class QueueConfig {
    public static final String COMMON_FANOUT_EXCHANGE_NAME = "common.fanout.exchange";
    public static final String COMMON_TOPIC_EXCHANGE_NAME = "common.topic.exchange";
    public static final String COMMON_QUEUE_NAME = "commonQueue.exchange";

    // 声明业务公共fanoutExchange
    @Bean("commonFanoutExchange")
    public FanoutExchange commonFanoutExchange() {
        return new FanoutExchange(COMMON_FANOUT_EXCHANGE_NAME);
    }

    // 声明业务公共topicExchange
    @Bean("commonTopicExchange")
    public TopicExchange commonTopicExchange() {
        return new TopicExchange(COMMON_TOPIC_EXCHANGE_NAME);
    }

    // 声明公共队列
    @Bean("commonQueue")
    public Queue commonQueue() {
        return new Queue(COMMON_QUEUE_NAME);
    }



    // 声明公共业务队列绑定关系Fanout
    @Bean
    public Binding commonFanoutBinding(@Qualifier("commonQueue") Queue queue,
                                    @Qualifier("commonFanoutExchange") FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }

    // 声明公共业务队列绑定关系Topic
    @Bean
    public Binding commonTopicBinding(@Qualifier("commonQueue") Queue queue,
                                    @Qualifier("commonTopicExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("");
    }
}
